package com.data.util

object LoginMethodUtils {

    /***
     * 查看传入的账号是什么类型
     * @param username
     * @return
     */
    fun accountType(username: String): String {
        val em = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"
        val ph = "^[1][3578]\\d{9}$"
        return when {
            username.matches(em.toRegex()) -> //邮箱登录
                FinalStringUtils.EMAIL
            username.matches(ph.toRegex()) -> //手机号登录
                FinalStringUtils.PHONE
            else -> //用户名登录
                FinalStringUtils.USERNAME
        }
    }

    /**
     * 根据传入的参数来组装Hql语句
     *
     * @param hql
     * @param params
     * @return
     */
    fun getHql(hql: StringBuilder, params: String): StringBuilder {
        when (params) {
            FinalStringUtils.PHONE -> hql.append("phone=?")
            FinalStringUtils.EMAIL -> hql.append("email=?")
            else -> hql.append("username=?")
        }
        return hql
    }


}
